home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DSIIC2.ARJ / HLP_MENU.C < prev    next >
C/C++ Source or Header  |  1991-07-15  |  6KB  |  283 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   HLP_MENU.C   ***************************/
  4.  
  5. /*
  6. link with:
  7. makehelp.c
  8. hlp_io.c
  9. */
  10.  
  11. #include "mydef.h"
  12.  
  13. #include "help.h"
  14. #include <stdio.h>
  15.  
  16. #if defined QUICKC
  17.  
  18. #include <malloc.h>
  19. #include <memory.h>
  20.  
  21. #endif
  22.  
  23. #if defined TURBOC
  24.  
  25. #include <string.h>
  26. #include <alloc.h>
  27. #include <mem.h>
  28. #include <ctype.h>
  29. #include <stdlib.h>
  30. #include <conio.h>
  31.  
  32. #endif
  33.  
  34. /* these functions create the menus used by makehelp.c */
  35.  
  36. void main_menu(void)   /* the main menu */
  37. {
  38. extern struct screen_structure scr;
  39. extern struct window_structure w[];
  40.  
  41. struct bar_struc main_menu [5]={
  42.     "Browse" ,"",browse,0,
  43.     "Add" ,"",add,0,
  44.     "New-file" ,"",file,0,
  45.     "Quit","",NULL,1,
  46.     "\0"
  47.   };
  48.  
  49.   status(0);
  50.  
  51.  bar_menu(main_menu,scr.inverse,scr.normal);
  52.  };
  53.  
  54.  
  55. int browse(void)     /* page browsing menu */
  56. {
  57. extern struct hlp help;
  58. extern struct screen_structure scr;
  59. extern struct window_structure w[];
  60.  
  61. int current_page=0;
  62. int done=FALSE;
  63. int last_load;
  64. int ret_code;
  65.  
  66.   struct bar_struc browse_menu [5]={
  67.     "Next " ,     "", NULL,1,
  68.     " Previous ", "", NULL,2,
  69.     " Edit " ,    "", NULL,3,
  70.     "Quit ",      "", NULL,4,
  71.     "\0"
  72.   };
  73.  
  74. if (help.number_pages==0) return(0);
  75.  
  76.   while(!done){
  77.     alt_screen(ON);
  78.     win_pop_top(help.edit);
  79.     scr.current=win_what_attr(help.edit);
  80.     load_page(current_page);
  81.      status(current_page+1);
  82.      win_pop_top(2);
  83.      alt_screen(OFF);
  84.  
  85.      ret_code=bar_menu(browse_menu,scr.inverse,scr.normal);
  86.  
  87.      switch(ret_code){
  88.        case 0: break;
  89.        case 1: current_page++;break;
  90.        case 2: current_page--;break;
  91.        case 3: cls(); win_pop_top(help.edit);
  92.          for(;;){
  93.  
  94.              /* get edit window attribute */
  95.           scr.current=win_what_attr(help.edit);
  96.            edit(1,1);  /* edit window */
  97.  
  98.            /* pop up the menu and status windows*/
  99.            win_pop_top(help.status);
  100.            win_pop_top(help.menu);
  101.            ret_code=verify_save();
  102.              if (ret_code==0)break;
  103.  
  104.               if(ret_code==1){
  105.                 save_page(current_page);
  106.                 break;
  107.               }
  108.  
  109.               if(ret_code==2)win_pop_top(help.edit);
  110.               if(ret_code==3) break;
  111.             }/* end for(;;) */
  112.              break;
  113.  
  114.        case 4: done=TRUE;
  115.  
  116.      }  /* end switch */
  117.  
  118.   if (current_page==help.number_pages)
  119.       current_page=help.number_pages-1;
  120.   if (current_page<0)current_page=0;
  121.  
  122.   } /* end while(!done)  */
  123.  
  124.  win_cls(help.edit);win_redraw_all();
  125.  status(0);  /* update status window */
  126.  return(0);
  127. }
  128.  
  129.  
  130. int file(void)      /* get the name of a new help file */
  131. {
  132. extern struct hlp help;
  133. extern struct screen_structure scr;
  134. extern struct window_structure w[];
  135.  
  136.  char old_name[80];
  137.  strcpy(old_name,help.filename);
  138.  get_name(help.filename);
  139.  if((strcmp(old_name,help.filename))!=0){
  140.    /* delete old edit window, create new one */
  141.    win_delete(help.edit);
  142.    help.edit= win_make(2,3,help.width,help.height,STD_FRAME,
  143.                       "Edit: Then 'Esc' ",scr.normal,scr.normal);
  144.      win_cls(help.status); /* clear status window */
  145.      status(0);            /* create new one */
  146.  }
  147.  return(0);
  148. }
  149.  
  150.  
  151. int verify_save(void)   /* verify the user wants to save the page */
  152. {
  153. extern struct hlp help;
  154. extern struct screen_structure scr;
  155. extern struct window_structure w[];
  156.  
  157. int return_code;
  158.  /* no function pointers, we want return codes only */
  159.   struct bar_struc main_menu [4]={
  160.     "Save",  "", NULL,1,
  161.     "Edit",  "", NULL,2,
  162.     "Quit" , "", NULL,3,
  163.  
  164.     "\0"
  165.   };
  166.  
  167.  return(bar_menu(main_menu,scr.inverse,scr.normal));
  168. }
  169.  
  170.  
  171. int add(void)   /* add a new help page */
  172. {
  173. extern struct hlp help;
  174. extern struct screen_structure scr;
  175. extern struct window_structure w[];
  176.  
  177. int done=FALSE;
  178. char *ptr=NULL;
  179. char *temp;
  180. char far *scrn_ptr;
  181. char ch;
  182. int i,j;
  183. int return_code;
  184.  
  185. cls();
  186.  
  187. win_pop_top(help.edit);
  188. scr.current=win_what_attr(help.edit);
  189.  
  190. /* allocate space, allow for \0 terminator */
  191. ptr=(char *)malloc ((help.width*help.height)*sizeof(char));
  192. status(help.number_pages+1);
  193. win_pop_top(help.edit);
  194. edit(1,1);
  195.  
  196. while(!done){
  197.   status(help.number_pages+1);
  198.   win_pop_top(help.menu);
  199.  
  200.   return_code=verify_save();   /* save file?*/
  201.  
  202.    if ( return_code==1){   /* save help page to file */
  203.      win_pop_top(help.edit);
  204.      /* scan the help window for characters */
  205.  
  206.       temp=ptr;    /* set temp pointer = pointer */
  207.  
  208.       for(i=0;i<help.height;i++){  /* get each row */
  209.  
  210.        scrn_ptr=(char far *)(scr.buffer+(scr.top+i-1)*
  211.                 (scr.columns*2)+2*(scr.left-1));
  212.  
  213.         for(j=0;j<help.width;j++){
  214.          *temp=*scrn_ptr;
  215.          temp++;scrn_ptr+=2;
  216.         }
  217.  
  218.        }
  219.        /* save image to file */
  220.       append(help.filename,ptr,(help.width*help.height*
  221.              sizeof(char)));
  222.       help.number_pages++;
  223.       ch=' ';
  224.  
  225.      status(help.number_pages+1);
  226.      win_pop_top(help.menu);
  227.  
  228.      ceol(1,1);
  229.      print(1,1, "Add another page ");
  230.      scr.bold_caps=TRUE;
  231.      print_here("Y/N? ");
  232.      scr.bold_caps=FALSE;
  233.      while(ch != 'Y' && ch !='N'){
  234.       ch=toupper(getch());
  235.      }
  236.  
  237.      if(ch=='N') done=TRUE;
  238.  
  239.      else{               /* edit a new page */
  240.         cls();
  241.         win_pop_top(help.edit);
  242.         cls();
  243.         edit(1,1);
  244.      }
  245.    } /* end return code==1 */
  246.  
  247.     if(return_code==2) {
  248.      win_pop_top(help.edit);
  249.      edit(1,1);
  250.     }
  251.     if(return_code==3){
  252.      done=TRUE;
  253.  
  254.     }
  255.  
  256. } /* end while !done */
  257.  
  258. if(ptr!=NULL)free(ptr);
  259. win_cls(help.menu);
  260. win_cls(help.edit);
  261. win_redraw_all(); status(0); return(0);
  262.  
  263. }
  264.  
  265. void status(int page)        /* display the status line */
  266. {
  267. extern struct hlp help;
  268. extern struct  screen_structure scr;
  269. extern struct window_structure w[];
  270.  
  271.  char string[20];
  272.  win_pop_top(help.status);
  273.  ceol(1,1);
  274.  scr.current=win_what_attr(help.status);
  275.  print(1,1,help.filename);
  276.  sprintf(string,"Page %3i of %d",page,help.number_pages);
  277.  
  278.  if(page>help.number_pages)
  279.   strcpy(string,"NEW-PAGE");
  280.  print(60,1,string);
  281.  win_pop_top(help.menu);
  282. }
  283.